package com.young.statemachine.handler;

import com.young.statemachine.domain.Work;
import com.young.statemachine.enums.WorkEvents;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.Message;
import org.springframework.statemachine.annotation.OnTransition;
import org.springframework.statemachine.annotation.WithStateMachine;
import org.springframework.stereotype.Service;

/**
 * @className: OrderStateChangeHandler
 * @author: Young
 * @date: 2025/1/15 23:22
 * @Version: 1.0
 * @description:
 */
@Slf4j
@Service
@WithStateMachine
public class OrderStateChangeHandler {

    @OnTransition(source = "UNREACHED",target = "REACHED")
    public void reachTransition(Message<WorkEvents> message){
        Work work = (Work) message.getHeaders().get("work");
        log.info("reach transition {}", work);
    }

    @OnTransition(source = "REACHED",target = "SCANNED")
    public void scanTransition(Message<WorkEvents> message){
        Work work = (Work) message.getHeaders().get("work");
        log.info("reach transition {}", work);
    }

    @OnTransition(source = "SCANNED",target = "TESTED")
    public void testTransition(Message<WorkEvents> message){
        Work work = (Work) message.getHeaders().get("work");
        log.info("reach transition {}", work);
    }

    @OnTransition(source = "TESTED",target = "RELEASED")
    public void releaseTransition(Message<WorkEvents> message){
        Work work = (Work) message.getHeaders().get("work");
        log.info("reach transition {}", work);
    }
}
